18. Check for Understanding: Data Structures

Check for Understanding

Let's pause again to do a quick check for understanding.

Which of the following statements about tuples are true? Select all that apply.

SOLUTION:
  • A tuple is an ordered data structure.
  • A tuple can be indexed and sliced like a list.

Which of the following statements about sets are true? Select all that apply.

SOLUTION:
  • A set is a mutable data structure.
  • A set does not contain duplicate elements.

Is the following statement true or false?
A set is the only data structure defined with curly braces: {}

SOLUTION: False

Which of the following statements about dictionaries are true? Select all that apply.

SOLUTION:
  • A dictionary is a mutable data structure.
  • A dictionary can be indexed using keys.
  • The keys of a dictionary are unique.

Quiz: Identify the Problem

Run the code below - it should break. Take a look at the error message and try to figure out what the issue is. Then, answer the quiz question below the editor.

Start Quiz:

# invalid dictionary - this should break
room_numbers = {
    ['Freddie', 'Jen']: 403,
    ['Ned', 'Keith']: 391,
    ['Kristin', 'Jazzmyne']: 411,
    ['Eugene', 'Zach']: 395
}

What's wrong with the code above?

SOLUTION: The dictionary is using a mutable datatype for its keys